package com.yztc.love_travel.adater;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.love_travel.R;
import com.yztc.love_travel.bean.PlayinLocalBean;
import com.yztc.love_travel.constant.URLConstant;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by My on 2016/11/29.
 */

public class PlayinLocalAdapter extends BaseAdapter {
    private List<PlayinLocalBean.ManualArticleListBean> mPlayinLocalBeanList;
    private Context context;

    public PlayinLocalAdapter(List<PlayinLocalBean.ManualArticleListBean> mPlayinLocalBeanList, Context context) {
        this.mPlayinLocalBeanList = mPlayinLocalBeanList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mPlayinLocalBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return mPlayinLocalBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh=null;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_listview_playinlocal, parent, false);
            vh=new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh= (ViewHolder) convertView.getTag();
        }
        PlayinLocalBean.ManualArticleListBean databean=mPlayinLocalBeanList.get(position);
        vh.textviewTitlePlayinlocal.setText(databean.getTitle());
        vh.textviewContentPlayinlocal.setText(databean.getContent());
        String coverFoto = databean.getCoverFoto();
        String url= URLConstant.PlayinLocal.URL_PLAYINLOCAL_PICTURE+coverFoto;
        if(!TextUtils.isEmpty(coverFoto)){
            Glide.with(context).load(url)
                    .placeholder(R.mipmap.logo)
                    .error(R.mipmap.logo)
                    .into(vh.imageviewPlayinlocal);
        }
        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.imageview_playinlocal)
        ImageView imageviewPlayinlocal;
        @BindView(R.id.textview_title_playinlocal)
        TextView textviewTitlePlayinlocal;
        @BindView(R.id.textview_content_playinlocal)
        TextView textviewContentPlayinlocal;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
